package com.alit.ibot.manager.attachement.util;

import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author litong
 * @date 2019年6月20日_下午7:13:28
 * @version 1.0
 * @desc
 */
public class FJSONUtil {

  /**
   * Map集合转为JSON数组
   * 
   * @param map
   * @return
   */
  public static <K, V> JSONArray mapToJSONArray(Map<K, V> map) {
    JSONArray retval = new JSONArray();
    for (Map.Entry<K, V> e : map.entrySet()) {
      JSONObject row = new JSONObject();
      row.put("id", e.getKey());
      row.put("url", e.getValue());
      retval.add(row);
    }
    return retval;
  }

  public static <K, V> JSONArray mapToJSONArray(Map<K, V> map, int start, int end) {
    JSONArray retval = new JSONArray();
    for(int i=start;i<end+1;i++) {
      
      JSONObject row = new JSONObject();
      row.put("id", i);
      row.put("url", map.get(i));
      retval.add(row);
    }
    
    return retval;
  }
}
